package cn.edu.ren.controller;

import cn.edu.ren.pojo.User;
import cn.edu.ren.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @PackageName: cn.edu.ren.controller
 * @ClassName: UserController
 * @Description:
 * @author: RZS
 * @date: 2021/5/20  17:31
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @GetMapping("/sel_all")
    public List<User> findAll(){
        return userService.findAll();
    }

    @GetMapping("/sel_id/{id}")
    public User findById(@PathVariable("id") Integer id){
        return userService.findById(id);
    }

    @PostMapping("/save")
    public List<User> addUser(User user){
        userService.addUser(user);
        return findAll();
    }

    @GetMapping("/sel_name")
    public User findByName(String name){
        return userService.findByName(name);
    }
}
